package com.andy.main.router_compiler.processor;

import com.google.auto.service.AutoService;

import java.util.Set;

import javax.annotation.processing.AbstractProcessor;
import javax.annotation.processing.Messager;
import javax.annotation.processing.ProcessingEnvironment;
import javax.annotation.processing.Processor;
import javax.annotation.processing.RoundEnvironment;
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.annotation.processing.SupportedSourceVersion;
import javax.lang.model.SourceVersion;
import javax.lang.model.element.TypeElement;
import javax.tools.Diagnostic;

/**
 * @version V1.0
 * @描述:
 * @Company:
 * @auth: Created by AN .
 * @time: 2020-03-12 19:52
 * @des
 */
//自动注册
@AutoService(Processor.class)
//当前注解处理器可以处理的注解
@SupportedAnnotationTypes({"com.andy.main.aptrouter.Route"})
//@SupportedAnnotationTypes({"com.andy.main.router_annotation.model.Route"})
//指定java版本
@SupportedSourceVersion(SourceVersion.RELEASE_7)
public class TestProcessor extends AbstractProcessor {

    Messager messager;
    //init方法相当于构造函数
    @Override
    public synchronized void init(ProcessingEnvironment processingEnv) {
        super.init(processingEnv);
        //日志打印需要通过message打印
        messager = processingEnv.getMessager();

        messager.printMessage(Diagnostic.Kind.NOTE, "TestProcessor=============init");
    }

    /**
     * {@inheritDoc}
     *
     * @param annotations
     * @param roundEnv
     */
    @Override
    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
        messager.printMessage(Diagnostic.Kind.NOTE,"TestProcessor=============process");
        for (TypeElement typeElement:annotations) {
            messager.printMessage(Diagnostic.Kind.NOTE,typeElement.getQualifiedName());
        }
        return false;
    }
}

